export default {
  methods: {
    filterArray(arr) {
      return arr.filter(val => !(!val || val === ''))
    },
    handleNodeAdd(node) {
      Object.assign(this.formPanel.add.model, this.initialAddModel)
      if (node) {
        this.currentNode = node
        this.formPanel.add.model[this.pidKey] = node.data[this.nodeIdKey]
        const params = {
          [this.idKey]: node.data[this.nodeIdKey]
        }
        this.getNodeInfo(params).then(({
          data
        }) => {
          this.fullPath = data.fullPath ? data.fullPath : '' + data.groupName
          this.$set(this.formPanel.add.model, 'fullPath', data.fullPath || '')
        })
      } else {
        this.formPanel.add.model[this.pidKey] = ''
      }
      this.dialogType = this.formPanel.add.type
    },
    handleNodeEdit(node) {
      this.cNode = []
      this.handleSelect(node)
      this.cNodeStr = this.cNode.join('\\')
      node && (this.currentNode = node)

      this.dialogType = this.formPanel.edit.type
      const params = {}
      params[this.idKey] = node.data[this.nodeIdKey]
      this.getNodeInfo(params).then(({
        data
      }) => {
        data.fullPath && (this.fullPath = data.fullPath)
        this.$refs.editForm && this.$refs.editForm.resetFields()
        Object.keys(this.formPanel.edit.model).forEach(key => {
          this.$set(this.formPanel.edit.model, key, '')
        })
        Object.assign(this.formPanel.edit.model, data)
        this.renderTreeCheckCallback()
      })
    },
    renderTreeCheckCallback() {
      this.editGroupId = this.formPanel.edit.model.groupId
    }
  }
}
